import java.io.Serializable;
import javax.swing.JTextArea;
import java.text.DecimalFormat;


public class Armour extends Item implements Entity, Serializable {

	private enum Kind { CAP, BOOTS, SHOES, LEGGINGS, GREAVES, CHESTPIECE, SHIRT, GAUNTLETS, GLOVES, PAULDRONS, PADDING, HELMET }
	private enum Material { BRONZE, IRON, STEEL, SILVER, BONE, LEATHER, CLOTH, SILK }
	private enum Quality { CRUDE, COMMON, SUPERIOR, EPIC, EXQUISITE, LEGENDARY }
	private enum Type { NONE, LIGHT, MEDIUM, HEAVY }
	private enum Slot { FEET, LEGS, CHEST, HANDS, SHOULDERS, HEAD }
	
	private Quality quality;
	private Kind kind;
	private Material material;
	private Type type;
	private Slot slot;
	
	private int Strength_Bonus;
	private int Agility_Bonus;
	private int Endurance_Bonus;
	private int Intelligence_Bonus;
	private int Willpower_Bonus;
	
	private double ArmourValue;
	
	private DecimalFormat df = new DecimalFormat("#.#");
	
	public Armour (String a, String b, String c, String d, String ... NameOverride) {
		super(a, b, c, d, 1);
		setQuality(b);
		setMaterial(c);
		setKind(d);
		calcValue();
		Weight = calcWeight();
		ArmourValue = calcArmour();
		setSlot();
		DisplayName = ("a " + b + " " + c + " " + d);
		Name = (b + " " + c + " " + d);
		Description = calcDescription();
		if (NameOverride.length == 1) {
			DisplayName = NameOverride[0];
			Name = DisplayName.substring(DisplayName.lastIndexOf(" ") + 1);
		} else if (NameOverride.length == 2) {
			DisplayName = NameOverride[0];
			Name = DisplayName.substring(DisplayName.lastIndexOf(" ") + 1);
			Description = NameOverride[1];
		}
	}
	
	public String calcDescription() {
		String result = null;
		switch (quality) {
		case CRUDE:
			result = ("It's a crudely fashioned " + material.toString().toLowerCase() + " " + kind.toString().toLowerCase() + ". It's clear that the craftsman was a novice or simply careless");
			if (material.toString().equalsIgnoreCase("silver")) {
				result = (result + ", though the silver content still makes it fairly valuable");
			} else {
			}
			break;
		case COMMON:
			result = ("It's a common " + material.toString().toLowerCase() + " " + kind.toString().toLowerCase() + ". The craftsmanship is about average in quality");
			if (material.toString().equalsIgnoreCase("silver")) {
				result = (result + ", though the silver content still makes it fairly valuable");
			} else {
			}
			break;
		case SUPERIOR:
			result = ("It's a well-crafted " + material.toString().toLowerCase() + " " + kind.toString().toLowerCase() + ", possibly made by a journeyman with some skill and experience");
			break;
		case EXQUISITE:
			result = ("It's a beautifully-made " + material.toString().toLowerCase() + " " + kind.toString().toLowerCase() + ". Intricate patterns and designs ornament the " + kind.toString().toLowerCase() + ", creating a highly pleasing effect on the eye");
			break;
		case EPIC:
			result = ("The quality of craftsmanship of this " + material.toString().toLowerCase() + " " + kind.toString().toLowerCase() + "is staggering. As you gaze upon the designs running across the " + kind.toString().toLowerCase() + ", it almost looks as though they are coming to life before your very eyes");
			break;
		case LEGENDARY:
			result = ("This " + material.toString().toLowerCase() + " " + kind.toString().toLowerCase() + " glows with inner power. You can feel your skin tingling from whatever enchantment this " + kind.toString().toLowerCase() + " is bestowed with");
			break;
		}
		return result;
	}
	
	public String getSlot() {
		return slot.toString();
	}
	
	public double calcWeight() {
		double baseweight = 0.0;
		
		switch (kind) {
		case CAP:
			baseweight = 1.0;
			break;
		case HELMET:
			baseweight = 1.5;
			break;
		case PAULDRONS:
			baseweight = 2.0;
			break;
		case PADDING:
			baseweight = 1.0;
			break;
		case CHESTPIECE:
			baseweight = 5.0;
			break;
		case SHIRT:
			baseweight = 1.0;
			break;
		case GAUNTLETS:
			baseweight = 1.5;
			break;
		case GLOVES:
			baseweight = 1.0;
			break;
		case LEGGINGS:
			baseweight = 2.0;
			break;
		case GREAVES:
			baseweight = 4.0;
			break;
		case SHOES:
			baseweight = 1.0;
			break;
		case BOOTS:
			baseweight = 1.5;
			break;
		default:
			baseweight = 2.0;
			break;
		}
		
		double materialmodifier = 0.0;
		
		switch (material) {
		case BONE:
			materialmodifier = 0.75;
			break;
		case SILK:
		case CLOTH:
			materialmodifier = 0.25;
			break;
		case LEATHER:
			materialmodifier = 0.5;
			break;
		case BRONZE:
			materialmodifier = 1.0;
			break;
		case IRON:
			materialmodifier = 1.20;
			break;
		case STEEL:
			materialmodifier = 1.30;
			break;
		case SILVER:
			materialmodifier = 1.40;
			break;
		default:
			materialmodifier = 1.0;
			break;
		}
		
		double result = baseweight * materialmodifier;
		return result;
	}
	
	public double calcArmour() {
		double Armour = 0.0;
		switch (quality) {
		case CRUDE:
			Armour = Weight * 1.0;
			break;
		case COMMON:
			Armour = Weight * 1.2;
			break;
		case SUPERIOR:
			Armour = Weight * 1.4;
			break;
		case EXQUISITE:
			Armour = Weight * 1.6;
			break;
		case EPIC:
			Armour = Weight * 1.8;
			break;
		case LEGENDARY:
			Armour = Weight * 2.0;
			break;
		default:
		}
		return Armour;
	}

	
	public void setQuality(String a) {
		for (Quality b : Quality.values()) {
			if (b.toString().equalsIgnoreCase(a)) {
				quality = b;
			}
		}
	}
	
	public void setMaterial(String a) {
		for (Material b : Material.values()) {
			if (b.toString().equalsIgnoreCase(a)) {
				material = b;
			}
		}
	}
	
	public void setKind(String a) {
		for (Kind b : Kind.values()) {
			if (b.toString().equalsIgnoreCase(a)) {
				kind = b;
			}
		}
	}
	
	public void setSlot() {
		switch (kind) {
		case CAP:
		case HELMET:
			slot = Slot.HEAD;
			break;
		case PADDING:
		case PAULDRONS:
			slot = Slot.SHOULDERS;
			break;
		case SHIRT:
		case CHESTPIECE:
			slot = Slot.CHEST;
			break;
		case GLOVES:
		case GAUNTLETS:
			slot = Slot.HANDS;
			break;
		case LEGGINGS:
		case GREAVES:
			slot = Slot.LEGS;
			break;
		case SHOES:
		case BOOTS:
			slot = Slot.FEET;
			break;
		default:
		}
	}
	
	public void setType(String a) {
		for (Type b : Type.values()) {
			if (b.toString().equalsIgnoreCase(a)) {
				type = b;
			}
		}
	}
	
	public double getArmourValue() {
		return ArmourValue;
	}
	
	public void addBonus(String a, int b) {
		if (a.equalsIgnoreCase("Strength")) {
			Strength_Bonus = b;
		} else if (a.equalsIgnoreCase("Endurance")) {
			Endurance_Bonus = b;
		} else if (a.equalsIgnoreCase("Agility")) {
			Agility_Bonus = b;
		} else if (a.equalsIgnoreCase("Intelligence")) {
			Intelligence_Bonus = b;
		} else if (a.equalsIgnoreCase("Willpower")) {
			Willpower_Bonus = b;
		}
	}
	
	public int getBonus(String a) {
		int result = 0;
		if (a.equalsIgnoreCase("Strength")) {
			result = Strength_Bonus;
		} else if (a.equalsIgnoreCase("Endurance")) {
			result = Endurance_Bonus;
		} else if (a.equalsIgnoreCase("Agility")) {
			result = Agility_Bonus;
		} else if (a.equalsIgnoreCase("Intelligence")) {
			result = Intelligence_Bonus;
		} else if (a.equalsIgnoreCase("Willpower")) {
			result = Willpower_Bonus;
		}
		return result;
	}
	
	public void Describe(JTextArea y) {
		y.append(Description + "." + "\n\n");
		y.append("Item Stats:\n\n");
		y.append("Armour value: " + df.format(ArmourValue) + "\n");
		if (getBonus("Strength") != 0) {
			y.append("Strength Bonus: " + getBonus("Strength") + "\n");
		}
		if (getBonus("Endurance") != 0) {
			y.append("Endurance Bonus: " + getBonus("Endurance") + "\n");
		}
		if (getBonus("Agility") != 0) {
			y.append("Agility Bonus: " + getBonus("Agility") + "\n");
		}
		if (getBonus("Intelligence") != 0) {
			y.append("Intelligence Bonus: " + getBonus("Intelligence") + "\n");
		}
		if (getBonus("Willpower") != 0) {
			y.append("Willpower Bonus: " + getBonus("Willpower") + "\n");
		}
		y.append("\nWeight: " + df.format(Weight) + "\n");
		y.append("Value: " + value);
	}
	
	public void calcValue() {
		double result = 0.0;
		double weapon_base_value = 0.0;
		switch (kind) {
		case CAP:
			weapon_base_value = 1.2;
			break;
		case HELMET:
			weapon_base_value = 1.5;
			break;
		case PADDING:
			weapon_base_value = 1.25;
			break;
		case PAULDRONS:
			weapon_base_value = 1.6;
			break;
		case SHIRT:
			weapon_base_value = 2.0;
			break;
		case CHESTPIECE:
			weapon_base_value = 5.0;
			break;
		case GLOVES:
			weapon_base_value = 1.2;
			break;
		case GAUNTLETS:
			weapon_base_value = 1.6;
			break;
		case LEGGINGS:
			weapon_base_value = 2.5;
			break;
		case GREAVES:
			weapon_base_value = 3.5;
			break;
		case SHOES:
			weapon_base_value = 1.5;
			break;
		case BOOTS:
			weapon_base_value = 1.5;
			break;
		default:
		}
		
		double material_value_modifier = 0.0;
		switch (material) {
		case BONE:
			material_value_modifier = 0.5;
			break;
		case BRONZE:
			material_value_modifier = 1.0;
			break;
		case IRON:
			material_value_modifier = 1.5;
			break;
		case STEEL:
			material_value_modifier = 2.0;
			break;
		case SILVER:
			material_value_modifier = 4.0;
			break;
		default:
			material_value_modifier = 1.0;
			break;
		}
		
		double quality_value_modifier = 0.0;
		
		switch (quality) {
		case CRUDE:
			quality_value_modifier = 0.5;
			break;
		case COMMON:
			quality_value_modifier = 1.0;
			break;
		case SUPERIOR:
			quality_value_modifier = 1.5;
			break;
		case EXQUISITE:
			quality_value_modifier = 3.0;
			break;
		case EPIC:
			quality_value_modifier = 5.0;
			break;
		case LEGENDARY:
			quality_value_modifier = 6.0;
			break;
		default:
			quality_value_modifier = 1.0;
			break;
		}
		
		result = ((weapon_base_value * material_value_modifier) * quality_value_modifier);
		super.value = (int) Math.rint(result);
		
	}
	
}
